# coding=utf-8
# 编译日期：2023-02-06 10:39:00
# 版权所有：www.i-search.com.cn
import ubpa.init_input as iinput
from ubpa.base_util import StdOutHook, ExceptionHandler
import ubpa.iautomation as iautomation
import ubpa.irobot as irobot
import ubpa.ikeyboard as ikeyboard
import ubpa.iie as iie
import ubpa.iwin as iwin
import ubpa.ibox as ibox
import ubpa.ics as ics
import time
import pdb
from ubpa.ilog import ILog
import getopt
from sys import argv
import sys
import os
from ubpa.base_img import *

class about_iSPRA:
     
    def __init__(self,**kwargs):
        self.__logger = ILog(__file__)
        self.path = set_img_res_path(__file__)
        self.robot_no = ''
        self.proc_no = ''
        self.job_no = ''
        self.input_arg = ''
        if('robot_no' in kwargs.keys()):
            self.robot_no = kwargs['robot_no']
        if('proc_no' in kwargs.keys()):
            self.proc_no = kwargs['proc_no']
        if('job_no' in kwargs.keys()):
            self.job_no = kwargs['job_no']
        ILog.JOB_NO, ILog.OLD_STDOUT = self.job_no, sys.stdout
        sys.stdout = StdOutHook(self.job_no, sys.stdout)
        ExceptionHandler.JOB_NO, ExceptionHandler.OLD_STDERR = self.job_no, sys.stderr
        sys.excepthook = ExceptionHandler.handle_exception
        if('input_arg' in kwargs.keys()):
            self.input_arg = kwargs['input_arg']
            if(len(self.input_arg) <= 0):
                self.input_arg = iinput.load_init(__file__)
            if self.input_arg is None:
                sys.exit(0)
        self.gv_1=None
      
    def Main(self):
        #应用
        self.__logger.dlogs(job_no=self.job_no,logmsg='Flow:Main,StepNodeTag:202211301635411641,Title:应用,Note:')
        ics.run_app(path='notepad.exe')
        time.sleep(1)
        #最大化窗口
        self.__logger.dlogs(job_no=self.job_no,logmsg='Flow:Main,StepNodeTag:2022113017143021813,Title:最大化窗口,Note:')
        tvar_2022113017143022214=iwin.do_win_maximize(waitfor=10.000)
        print('[Main] [最大化窗口] [SNTag:2022113017143021813]  返回值：[' + str(type(tvar_2022113017143022214)) + ']' + str(tvar_2022113017143022214))
        # 序列
        self.__logger.dlogs(job_no=self.job_no, logmsg='Flow:Main,StepNodeTag:2022120810544712111,Title:序列,Note:')
        #流程运行中，请勿操作
        self.__logger.dlogs(job_no=self.job_no,logmsg='Flow:Main,StepNodeTag:2022121414242526244,Title:流程运行中，请勿操作,BzTag:c54ac73d44be424a875d92fe0ab6779f,Note:')
        irobot.send_robot_workflow(sz_tag='c54ac73d44be424a875d92fe0ab6779f',sz_message='流程运行可能有略微延迟，请勿操作鼠标或窗口',sz_title='流程运行中，请勿操作')
        #设置文本
        self.__logger.dlogs(job_no=self.job_no,logmsg='Flow:Main,StepNodeTag:2022113017173972016,Title:设置文本,Note:')
        selectorJson={"selector":[{"ControlType":"编辑","ControlTypeID":"0xC354","Index":"1"}]}
        iautomation.set_text(waitfor=1.000,win_name=r'无标题 - 记事本',win_class=r'Notepad',text=r'iS-RPA( i-Search Robotic Process Automation )是艺赛旗自主研发、拥有独立知识产权的RPA产品，旨在为企业解决业务流程自动化难题，减少人为从事标准而又重复、繁琐且大批量的工作任务。',selector=selectorJson)
        time.sleep(1)
        #模拟按键
        self.__logger.dlogs(job_no=self.job_no,logmsg='Flow:Main,StepNodeTag:2022121911283564437,Title:模拟按键,Note:')
        ikeyboard.key_send_cs(waitfor=10.000,win_title=r'*无标题 - 记事本',text='{end}')
        #热键输入
        self.__logger.dlogs(job_no=self.job_no,logmsg='Flow:Main,StepNodeTag:2022120813581374523,Title:热键输入,Note:')
        ikeyboard.key_send_cs(waitfor=10.000,win_title=r'*无标题 - 记事本',text=r'^{ENTER}')
        #模拟按键
        self.__logger.dlogs(job_no=self.job_no,logmsg='Flow:Main,StepNodeTag:2022121413533255925,Title:模拟按键,Note:')
        ikeyboard.key_send_cs(waitfor=10.000,win_title=r'*无标题 - 记事本',text='通过“设计器+控制台+机器人”的完美组合，可以实现任意流程自动化，提高工作学习效率。')
        time.sleep(1)
        #模拟按键
        self.__logger.dlogs(job_no=self.job_no,logmsg='Flow:Main,StepNodeTag:2022121911301477346,Title:模拟按键,Note:')
        ikeyboard.key_send_cs(waitfor=10.000,win_title=r'*无标题 - 记事本',text='{end}')
        #热键输入
        self.__logger.dlogs(job_no=self.job_no,logmsg='Flow:Main,StepNodeTag:2022121413580439527,Title:热键输入,Note:')
        ikeyboard.key_send_cs(waitfor=10.000,win_title=r'*无标题 - 记事本',text=r'^{ENTER}')
        #模拟按键
        self.__logger.dlogs(job_no=self.job_no,logmsg='Flow:Main,StepNodeTag:2022121413580439529,Title:模拟按键,Note:')
        ikeyboard.key_send_cs(waitfor=10.000,win_title=r'*无标题 - 记事本',text='本案例中，你可以重点感受不同组件组合之后的神奇之处！')
        time.sleep(1)
        #您可点击“确定”
        self.__logger.dlogs(job_no=self.job_no,logmsg='Flow:Main,StepNodeTag:2022121414395058920,Title:您可点击“确定”,BzTag:4edbfdb5e2804c48809943adb34090e3,Note:')
        irobot.send_robot_workflow(sz_tag='4edbfdb5e2804c48809943adb34090e3',sz_title='您可点击“确定”')
        #消息框
        self.__logger.dlogs(job_no=self.job_no,logmsg='Flow:Main,StepNodeTag:2022113017425221019,Title:消息框,Note:')
        tvar_2022113017425221420=ibox.msgs_box('是否访问艺赛旗官网，了解更多信息',title=r'艺赛旗',timeout=0)
        print('[Main] [消息框] [SNTag:2022113017425221019]  返回值：[' + str(type(tvar_2022113017425221420)) + ']' + str(tvar_2022113017425221420))
        #强行关闭窗口
        self.__logger.dlogs(job_no=self.job_no,logmsg='Flow:Main,StepNodeTag:2022113018081550329,Title:强行关闭窗口,Note:')
        tvar_2022113018081550530=iwin.do_win_kill(waitfor=10.000,win_title=r'*无标题 - 记事本')
        print('[Main] [强行关闭窗口] [SNTag:2022113018081550329]  返回值：[' + str(type(tvar_2022113018081550530)) + ']' + str(tvar_2022113018081550530))
        #网站
        self.__logger.dlogs(job_no=self.job_no,logmsg='Flow:Main,StepNodeTag:2022113018055478825,Title:网站,Note:')
        iie.open_url(ie_path='C:/Program Files (x86)/Internet Explorer/iexplore.exe',url='https://www.i-search.com.cn/')
 
if __name__ == '__main__':
    ILog.begin_init()
    robot_no = ''
    proc_no = ''
    job_no = ''
    input_arg = ''
    try:
        argv = sys.argv[1:]
        opts, args = getopt.getopt(argv,"hr:p:j:i:",["robot = ","proc = ","job = ","input = "])
    except getopt.GetoptError:
        print ('robot.py -r <robot> -p <proc> -j <job>')
    for opt, arg in opts:
        if opt == '-h':
            print ('robot.py -r <robot> -p <proc> -j <job>')
        elif opt in ("-r", "--robot"):
            robot_no = arg
        elif opt in ("-p", "--proc"):
            proc_no = arg
        elif opt in ("-j", "--job"):
            job_no = arg
        elif opt in ("-i", "--input"):
            input_arg = arg
    pro = about_iSPRA(robot_no=robot_no,proc_no=proc_no,job_no=job_no,input_arg=input_arg)
    pro.Main()
